package pers.cz.menu;

import pers.cz.cache.BaseDataCache;
import pers.cz.mapper.MenuMapper;
import pers.cz.model.Menu;
import pers.cz.pub.BeanHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 * @program: PostGirl-panent
 * @description: MenuService
 * @author: Cheng Zhi
 * @create: 2021-04-14 14:08
 **/
@Service
public class MenuService {

    @Autowired
    BeanHelper beanHelper;

    @Autowired
    BaseDataCache baseDataCache;

    public List<Menu> getAllMenuByUserId(Integer id) {

        List<Menu> menuList = beanHelper.getBean(MenuMapper.class).queryAllMenuByUserId(id);
        return  menuList;
    }

    public List<Menu> selectAllMenuByRole() {

        List<Menu> menuList = baseDataCache.getAllMenuByRoleFromCache();
        return menuList;
    }

    /**
     * 获取所有的根节点菜单
     * @return
     */
    public List<Menu> getAllParentMenu() {

        List<Menu> menuList = beanHelper.getBean(MenuMapper.class).getAllParentMenu();
        return menuList;
    }

    /**
     * 查询所有叶子节点
     * @param parentId
     * @return
     */
    public List<Menu> getMenuByParentId(Integer parentId) {
        return beanHelper.getBean(MenuMapper.class).getMenuByParentId(parentId);
    }
}
